using Godot;
using System;

public partial class StoryItem : MarginContainer
{
  TextureButton button;

  ColorRect colorRect;

  public int Index = 0;

  public ChooseStory Root;

  private Color defaultColor;
  public override void _Ready()
  {
    button = GetNode<TextureButton>("TextureButton");
    colorRect = GetNode<ColorRect>("ColorRect");
    button.Pressed += OnClick;
    defaultColor = colorRect.Color;
  }

  private void OnClick()
  {
    foreach (var item in GetParent().GetChildren())
    {
      item.Call("ResetColor");
    }
    SetColor();
    Root.CurrentStoryIndex = Index;
  }

  public void SetColor()
  {
    colorRect.Color = Colors.SeaGreen;
  }

  public void ResetColor()
  {
    colorRect.Color = defaultColor;
  }
}
